home *** CD-ROM | disk | FTP | other *** search
- // generic JGNE.c, by Kevin Irlen, Symantec Corp. 7/93
-
- /*
- Add this file to a project of type Code Resource. Set Type to CODE, ID to 128,
- and check the "Locked" and "System Heap" attributes. Optionally, set Creator to RSED
- and File Type to rsrc so you can open this with ResEdit. Add this file.
-
- When building the resource, "Merge" it into your INIT, or into your manual install
- project's resource file.
- */
-
- short myJGNEFilterFunc(short hasEvent,const EventRecord *anEvent);
-
- /*
- The generic JGNE INIT code expects main (i.e. the main entry point in
- the code resource) to be exactly as follows. It relies on knowing the
- the exact location of the dummy movea.l instruction, which it must overwrite.
- */
-
- // This generic JGNE does the SetupA4 stuff necessary so you can use statics
- // or globals, if desired.
-
- main()
- {
- asm
- {
- move.l A1 ,-(SP) ; A1 holds theEvent
- move.w 8(SP),-(SP) ; 8(SP) holds hasEvent (4(SP) + 4 we just pushed)
- jsr myJGNEFilterFunc
- move.w D0,10(SP) ; put return value back at what will be 4(SP)
- addq.l #2,SP ; pop hasEvent (10 - 2 = 8)
- move.l (SP)+,A1 ; pop theEvent back into A1 ( 8 - 4 = 4)
- movea.l #0xFFFFFFFF,A0 ; this gets overwritten at INIT time with either the
- jmp (A0) ; next JGNE's address, or an RTS if there isn't one!
- }
- }
-
- #include <SetUpA4.h> // DO NOT move this before main! (It generates code.)
-
-
- short myJGNEFilterFunc(short hasEvent,const EventRecord *theEvent)
- {
- char theChar;
-
- RememberA0(); SetUpA4();
-
- if (hasEvent)
- {
- switch (theEvent->what)
- {
- // Handle your events here. Set hasEvent to 0 if you don't want the event
- // you handled to be passed to the next JGNE or the current application.
- // This code beeps any time the user types cmd-shift j, g, n, or e!
-
- case keyDown:
- case autoKey:
-
- theChar = theEvent->message & charCodeMask;
-
- if ((theEvent->modifiers & cmdKey) && (theEvent->modifiers & shiftKey))
- if ((theChar == 'j') || (theChar == 'g') || (theChar == 'n') || (theChar == 'e'))
- {
- SysBeep(10);
-
- hasEvent = 0;
- }
-
- default:
- break;
- }
- }
- RestoreA4();
-
- return hasEvent;
- }
-
- /*
-
- NOTE:
-
- If you install the above jGNE and attempt to make use of it when a DA is the
- front window, you'll be in for a nasty surprise. It won't work! For some
- reason beyond my comprehension, DA's do not send keyDown events through
- GetNextEvent in the documented way; specifically, hasEvent does not get set.
-
- The simple solution is:
-
- Remove the test for hasEvent, and just go straight to examining the event
- record, which will contain the proper information (and *should* be empty if
- there's no event).
-
- In fact, there doesn't seem to be much reason to have the test for hasEvent at
- all, other than to bypass the switch statement, and possibly to allow you to
- try to steal events from other jGNE's that happen to be loaded after yours (not
- a very sensible thing to try to do). I've left it in, mostly for form's sake,
- and in hopes that the problem might motivate someone to find an answer to the
- DA mystery! On the other hand, you might even take it out of the call to the
- filter function altogether, remove it from the assembly in main, change the
- offset it the installer program, etc....
-
- */
-
-